package com.example.tool.activtiy.recylerview;

import android.support.v4.view.ViewCompat;
import android.support.v7.widget.CardView;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.example.tool.R;
import com.example.tool.activtiy.base.BaseActivity;
import com.example.tool.adapter.WidgetAdapter;
import com.example.tool.adapter.base.CommonAdapter;
import com.example.tool.adapter.base.CommonViewHolder;
import com.example.tool.mvp.CommonPresent;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * Created Date 2019/8/25.
 *
 * @author liangkun
 * ClassDescription：普通单条目
 */
public class RecylerViewActivity extends BaseActivity<CommonPresent> {
    @BindView(R.id.rv_recyclerview)
    protected RecyclerView recyclerView;
    private List<String> mDatas = new ArrayList<>();
    private WidgetAdapter widgetAdapter;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_recylerview;
    }

    @Override
    protected void initView() {
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
//        recyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
//        recyclerView.addItemDecoration(new RecycleViewDivider(mContext, DividerItemDecoration.VERTICAL, getResources().getDimensionPixelOffset(R.dimen.sw_dp_5), 0, 0, mContext.getResources().getColor(R.color.color_transpare)));
        widgetAdapter = new WidgetAdapter(this, new ArrayList<String>(), R.layout.activity_anim_item);
        recyclerView.setAdapter(widgetAdapter);
    }

    @Override
    protected void initData() {
        initDatas();

    }



    @Override
    protected void initEvent() {
        widgetAdapter.setOnItemClickListener(new CommonAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, CommonViewHolder holder, int position) {
                ((CardView) view).setCardBackgroundColor(getResources().getColor(R.color.color_white));
                ((CardView) view).setCardElevation(getResources().getDimensionPixelOffset(R.dimen.sw_dp_8));
                ViewCompat.animate(view).scaleX(1.07f).scaleY(1.07f).start();

            }

            @Override
            public boolean onItemLongClick(View view, CommonViewHolder holder, int position) {
                return false;
            }
        });
    }

    @Override
    protected CommonPresent createPresenter() {
        return null;
    }

    /**
     * 获取数据
     */
    private void initDatas() {
        for (int i = 'A'; i <= 'z'; i++) {
            mDatas.add((char) i + "");
        }
        widgetAdapter.updataData(mDatas);
    }


}
